package com.dycx.api.controller.manage.message;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dycx.common.RestResponse;
import com.dycx.message.dto.TemplateDTO;
import com.dycx.message.service.TemplateService;
import com.dycx.message.vo.TemplateVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping(value = "/manage/message/template")
public class TemplateController {

    @Resource
    private TemplateService templateService;

    /**
     * 添加
     **/
    @PostMapping("/addTemplate")
    public RestResponse<Boolean> addTemplate(@RequestBody @Valid TemplateDTO templateDTO) {
        return templateService.addTemplate(templateDTO) ? RestResponse.success() : RestResponse.fail();
    }

    /**
     * 修改
     **/
    @PostMapping("/updateTemplate")
    public RestResponse<Boolean> updateTemplate(@RequestBody TemplateDTO templateDTO) {
        return templateService.updateTemplate(templateDTO) ? RestResponse.success() : RestResponse.fail();
    }

    /**
     * 删除
     **/
    @GetMapping("/deleteTemplate")
    public RestResponse<Boolean> deleteTemplate(int id) {
        return templateService.removeById(id) ? RestResponse.success() : RestResponse.fail();
    }

    /**
     * 分页
     **/
    @PostMapping("/getPage")
    public RestResponse<Page<TemplateVO>> getPage(@RequestBody TemplateDTO templateDTO) {
        return RestResponse.success(templateService.getPage(templateDTO));
    }

    /**
     * 模版列表
     **/
    @GetMapping("/getEnableList")
    public RestResponse<List<Map<String,Object>>> getEnableList(Integer messageType) {
        return RestResponse.success(templateService.getEnableList(messageType));
    }


    /**
     * 同步模版
     **/
    @GetMapping("/syncTemplate")
    public RestResponse<Boolean> syncTemplate() {
        templateService.syncTemplate();
        return RestResponse.success();
    }
}
